﻿<common:LayoutAwarePage x:Class="KouDai.WinPad.Views.MainPage"
                        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                        xmlns:WRCControl="using:WRCControl"
                        xmlns:WinRTControl="using:WinRTControl"
                        xmlns:cal="using:Caliburn.Micro"
                        xmlns:common="using:KouDai.WinPad.Common"
                        xmlns:converter="using:KouDai.WinPad.Converter"
                        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                        xmlns:i="using:Windows.UI.Interactivity"
                        xmlns:local="using:KouDai.WinPad.Views"
                        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                        xmlns:vm="using:KouDai.WinPad.ViewModels"
                        x:Name="pageRoot"
                        cal:Bind.AtDesignTime="True"
                        d:DataContext="{d:DesignInstance IsDesignTimeCreatable=True,
                                                         Type=vm:MainPageViewModel}"
                        mc:Ignorable="d">

    <Page.Resources>

        <converter:ThicknessConverter x:Key="MarginConverter" />

    </Page.Resources>

    <Grid Style="{StaticResource LayoutRootStyle}">
        <Grid.RowDefinitions>
            <RowDefinition Height="140" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>


        <VisualStateManager.VisualStateGroups>

            <!--  Visual states reflect the application's view state  -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape" />
                <VisualState x:Name="Filled" />

                <!--  The entire page respects the narrower 100-pixel margin convention for portrait  -->
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="GoBack" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}" />
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemGridView" Storyboard.TargetProperty="Padding">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="96,136,86,56" />
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>

                <!--
                    The back button and title have different styles when snapped, and the list representation is substituted
                    for the grid displayed in all other view states
                -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="GoBack" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}" />
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="DisplayName" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}" />
                        </ObjectAnimationUsingKeyFrames>

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemListView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible" />
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemGridView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed" />
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>

        <WRCControl:RTNPullBottomPanel x:Name="Panel" cal:Message.Attach="[Event ScrollBottom] = [Action GetImageWall]" />

        <!--  Horizontal scrolling grid used in most view states  -->
        <GridView x:Name="itemGridView"
                  Grid.RowSpan="2"
                  AutomationProperties.AutomationId="ItemsGridView"
                  AutomationProperties.Name="Items"
                  IsSwipeEnabled="false"
                  ItemsSource="{Binding Items}"
                  Padding="116,136,116,46"
                  SelectionMode="None"
                  TabIndex="1">
            <GridView.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapGrid Margin="0,30,0,0"
                              VerticalAlignment="Center"
                              ItemHeight="265"
                              ItemWidth="240"
                              Orientation="Vertical"
                              VerticalChildrenAlignment="Center" />
                </ItemsPanelTemplate>
            </GridView.ItemsPanel>
            <GridView.ItemTemplate>
                <DataTemplate>
                    <Grid Width="{Binding Width}"
                          Height="{Binding Height}"
                          Margin="{Binding Margin,
                                           Converter={StaticResource MarginConverter}}"
                          Background="{StaticResource ImageWallBackBrush}">

                        <Image Source="{Binding ImageUrlForIphone}" Stretch="UniformToFill" />
                        <Border Margin="0,0,0,10"
                                HorizontalAlignment="Left"
                                VerticalAlignment="Bottom"
                                Background="{StaticResource PriceBackgroundBrush}">
                            <TextBlock Margin="5,0"
                                       HorizontalAlignment="Left"
                                       FontFamily="Arial"
                                       FontSize="18.667"
                                       Foreground="{StaticResource CommonWhiteBrush}"
                                       Text="{Binding Price}" />
                        </Border>
                    </Grid>
                </DataTemplate>
            </GridView.ItemTemplate>

        </GridView>


        <!--  Vertical scrolling list only used when snapped  -->
        <ListView x:Name="itemListView"
                  Grid.Row="1"
                  Margin="0,10,0,0"
                  AutomationProperties.AutomationId="ItemsListView"
                  AutomationProperties.Name="Items"
                  IsSwipeEnabled="false"
                  ItemsSource="{Binding Items}"
                  Padding="10,0,0,60"
                  SelectionMode="None"
                  TabIndex="1"
                  Visibility="Collapsed">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <Grid Width="300"
                          Height="300"
                          Background="{StaticResource ImageWallBackBrush}">
                        <Image Source="{Binding ImageUrlForIphone}" Stretch="UniformToFill" />
                        <Border VerticalAlignment="Bottom"
                                Background="{StaticResource PriceBackgroundBrush}"
                                BorderThickness="1">
                            <TextBlock Margin="5,0"
                                       FontFamily="Arial"
                                       FontSize="15"
                                       Foreground="{StaticResource CommonWhiteBrush}"
                                       Text="{Binding Price}"
                                       TextWrapping="Wrap" />
                        </Border>
                    </Grid>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

        <!--  Back button and page title  -->
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Button x:Name="GoBack" Style="{StaticResource BackButtonStyle}" />
            <TextBlock x:Name="DisplayName"
                       Grid.Column="1"
                       FontFamily="Segoe UI Symbol"
                       Style="{StaticResource PageHeaderTextStyle}"
                       Tapped="PageTitleTapped" />
            <Border Grid.ColumnSpan="2"
                    VerticalAlignment="Bottom"
                    BorderBrush="#FFEFEFEF"
                    BorderThickness="1,1,1,1" />

        </Grid>
    </Grid>
</common:LayoutAwarePage>
